﻿using System;
using System.Reflection;

namespace RoughJs.Ast
{
    public class VMBridge2 : VMBridge
    {
        object[] storage = new object[1];
        public override object getThreadContextHelper()
        {
            if (storage == null)
            {
                storage = new Object[1];
            }
            return storage;
        }

        public override Context getContext(object contextHelper)
        {
            Object[] storage = (Object[])contextHelper;
            return (Context)storage[0];
        }

        public override void setContext(object contextHelper, Context cx)
        {
            Object[] storage = (Object[])contextHelper;
            storage[0] = cx;
        }

        public override object getCurrentThreadClassLoader()
        {//这里返回类加载器，这个类.net里面没有
            return null;
        }

        public override bool tryToMakeAccessible(object accessibleObject)
        {//这里可能还需要对字段进行判断
            //if (!(accessibleObject is PropertyInfo))
            //{
            //    return false;
            //}
            //PropertyInfo accessible = (PropertyInfo)accessibleObject;
            //if (accessible.CanRead)
            //{
            //    return true;
            //}

            //return accessible.CanRead;
            return false;//因为在.net中反射可以反射任何对象，如果不可以反射，那就肯定有异常
        }


        public override bool isVarArgs(MethodBase member)
        {
        //    if (member is MethodInfo)
        //    return ((MethodInfo) member).isp;
        //else if (member is ConstructorInfo)
        //    return ((ConstructorInfo) member).isVarArgs();
        //else 
        //    return false;
            return false;
        }
    }
}
